package com.example.recyclerviewproject;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class MyAdapter2 extends RecyclerView.Adapter<MyAdapter2.MyViewHolder2> {
    private  Context mContext;
    private List<ItemBean> mList;

    public  MyAdapter2(Context context){
        this.mContext=context;
    }

    public  void setList(List<ItemBean> list){
        this.mList=list;
    }
    @NonNull
    @Override
    public MyViewHolder2 onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.list_item_layout3, parent, false);
        MyViewHolder2 myViewHolder2 = new MyViewHolder2(view);
        return myViewHolder2;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder2 holder, int position) {
        ItemBean itemBean = mList.get(position);
        holder.title_tv.setText(itemBean.getTitle());
        holder.content_tv.setText(itemBean.getContent());
        holder.icon_img.setImageResource(itemBean.getImageInt());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class  MyViewHolder2 extends  RecyclerView.ViewHolder{
        ImageView icon_img;
        TextView title_tv;

        TextView content_tv;

        public MyViewHolder2(@NonNull View itemView) {
            super(itemView);
            icon_img= itemView.findViewById(R.id.icon_img);
            title_tv = itemView.findViewById(R.id.title_tv);
            content_tv=itemView.findViewById(R.id.content_tv);
        }
    }
}
